package com.bishe.demo.modules.ticket.service.impl;

import com.bishe.demo.modules.common.dao.CityDao;
import com.bishe.demo.modules.common.entity.City;
import com.bishe.demo.modules.ticket.dao.TicketSiteDao;
import com.bishe.demo.modules.ticket.entity.TicketSite;
import com.bishe.demo.modules.ticket.service.TicketSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;


/**
 * @Description TicketSiteImpl
 * @Author YHQ
 * @Date 2021/4/1 10:29
 */
@Service
@Transactional
public class TicketSiteImpl implements TicketSiteService {
    @Autowired
    private TicketSiteDao ticketSiteDao;
    @Autowired
    private CityDao cityDao;

    //通过中间表id查票数据
    @Override
    public List<TicketSite> getTicketSiteBySmId(Integer sMId) {
        List<TicketSite>ticketSite = ticketSiteDao.getTicketSiteBySmId(sMId);
        List<TicketSite> list = new LinkedList<>();
        for (TicketSite site : ticketSite) {
            List<City> list1 = new LinkedList<>();
            List<Integer> fkCityIds = ticketSiteDao.getFkCityIdBySMId(sMId);
            for (Integer fkCityId : fkCityIds) {
                City city = cityDao.getCitiesByFkCityId(fkCityId);
                list1.add(city);
            }
            site.setCities(list1);
            list.add(site);
        }
        return list;
    }
    //通过中间表id查看时间外键
    @Override
    public List<Integer> getFkTimeIdBySMId(Integer sMId) {
        return ticketSiteDao.getFkTimeIdBySMId(sMId);
    }
    //通过中间表id查看地点外键
    @Override
    public List<Integer> getFkCityIdBySMId(Integer sMId) {
        return ticketSiteDao.getFkCityIdBySMId(sMId);
    }


}
